<script src='<?php echo DIR_JS?>ui.datepicker.js' type='text/javascript' language='javascript'> </script>

<div class="section" id="sitemaplist">
  <div class="section-title">Danh sách khách hàng mà nhân viên phát hành báo phụ trách</div>
  <div class="section-content padding1">

      <?php if($_GET['print'] !="true" ){ ?>
      <div class="button right"> 
      	<a class="button print" id="btnPrint" >In</a> 
      	<a class="button exit" href="?route=deliman/home">Đóng</a>
      </div>
      <div class="clearer">^&nbsp;</div>
      <?php } ?>
      
      <div id="error" class="error" style="display:none"></div>
      
      <?php 
      if($_GET['print'] !="true" ){ 
      	if(trim($loainhanvienid)!='3')
        {
      
      ?>
      
      <form name="frm" id="frm" action="<?php echo $action?>" method="post" enctype="multipart/form-data">
     <!-- <input type="hidden" id="diachi" name="diachi" value="" class="text" />
      <input type="hidden" name="khachhangid" value="<?php echo $item['khachhangid']?>">
      <input type="hidden" name="id" value="<?php echo $item['id']?>">-->
      <div >
      

        <div id="formtimkiem" style="margin-bottom:50px;">
          <label>Khu Vực:</label>
          <select name="khuvucid" id="khuvucid">
            <option value="">---Chọn tất cả---</option>
            <?php       
                        
                        foreach($dskhuvuc as $khuvuc)
                        { 
                        ?>
            <option value="<?php echo $khuvuc['khuvucid']?>"> <?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$khuvuc['level'])?> <?php echo $khuvuc['tenkhuvuc']?> </option>
            <?php 
                        }
                        ?>
          </select>
          
          <label>Nhân viên giao báo:</label>
          <select id="nhanvienid" name="nhanvienid">
          </select>
          <!--
          <label>Ngày phụ trách: từ</label>
          <script language="javascript">
                        $(function() {
                            $("#tungay").datepicker({
                                    changeMonth: true,
                                    changeYear: true,
                                    dateFormat: 'dd-mm-yy'
                                    });
                            $("#denngay").datepicker({
                                    changeMonth: true,
                                    changeYear: true,
                                    dateFormat: 'dd-mm-yy'
                                    });
                            });
                        </script>
          <input type="text" id="tungay" name="tungay" class="text" />
          <label>đến:</label>
          <input type="text" id="denngay" name="denngay" class="text" />
          -->
          &nbsp; <a class="button-other search" style="margin-bottom:-30px" onClick="searchForm()"></a> </div>
        
      </div>
    </form>
    <?php } } ?>
    	<table class="data-table" width="100%">
          <thead>
            <tr>
              <th>STT</th>
              <th>Khách hàng</th>
              <th>Địa chỉ</th>
              <th>Email</th>
              <th>Điện thoại</th>
              <th>Nhân viên</th>
            </tr>
          </thead>
          <?php
            	$index = 1;
            	foreach($datas as $item)
                {
            ?>
          <tbody>
            <tr>
              <td><?php echo $index++?></td>
              <td><?php echo $item['hoten'] ?></td>
              <td><?php echo $item['diachi'] ?></td>
              <td><?php echo $item['email'] ?></td>
              <td><?php echo $item['dienthoai'] ?></td>
              <td><?php echo $item['tennhanvienphutrach'] ?></td>
            </tr>
          </tbody>
          <?php
            	}
            ?>
        </table>
  </div>
</div>
<script language="javascript">

$(document).ready(function(){
		$('#khuvucid').change(function(){
			$('#nhanvienid').load('?route=deliman/capnhatkybaodagiao/getnhanvien&khuvucid='+$('#khuvucid').val(),function(){
					$("#nhanvienid").val("<?php echo $_GET['nhanvienid']?>");
				});
		
		});
		$('#khuvucid').change();
		$('.btnConfirm').click(function(){
			//alert($(this).attr('ref'));
			//Gui request len sever
			$.post("?route=deliman/capnhatkybaodagiao/updatethongtindatbao", 
			{
				id:$(this).attr('ref'),
				trangthai:$('#trangthai'+$(this).attr('ref')).val(),
			},
			
			function(data){
				//Hien thi ngay server tra ve
				alert('Cap nhat thanh cong');
				/*//alert(data);
				obj = jQuery.parseJSON(data);
				id=obj.id;
				trangthai = obj.trangthai;
				$('#trangthai'+id).val(trangthai);*/
		
		});			
	});
});

function searchForm()
{
	var url ="?route=deliman/danhsachkhachhangmanhanvienphathanhbaophutrach";
		
	/*if($("#tungay").val() != "")
		url += "&tungay="+ $("#tungay").val();
	if($("#denngay").val() != "")
		url += "&denngay=" + $("#denngay").val();*/
	if($("#khuvucid").val() != "")
		url += "&khuvucid=" + $("#khuvucid").val();
	if($("#nhanvienid").val() != "")
		url += "&nhanvienid=" + $("#nhanvienid").val();
	
	window.location = url;
}

/*$("#tungay").val("<?php echo $_GET['tungay']?>");
$("#denngay").val("<?php echo $_GET['denngay']?>");*/

$("#khuvucid").val("<?php echo $_GET['khuvucid']?>");


$('#btnPrint').click(function(){
	
	var url = window.location+"&print=true";
	 var result = window.showModalDialog(url,"", "dialogWidth:1000px; dialogHeight:450px; center:yes");
});


</script>

<?php if($_GET['print'] =="true" ){ ?>
	<script language="javascript">
        window.print();
    </script>
<?php } ?>